﻿package mortal.game.view.copy.groupCopy
{
    import Message.Public.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.net.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class GroupCopyIcon extends ActionBaseIcon
    {
        private var _isNeedToUpdate:Boolean;
        private static var _instance:GroupCopyIcon;

        public function GroupCopyIcon()
        {
            super(ResFileConst.GroupCopyIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.name = "GroupCopyIcon";
            this.showLeftEnterNum();
            this.showGroupRwEffect();
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLevel, this.showLeftEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.CopyEnterTimesUpdate, this.showLeftEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.showLeftEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.SingleTowerGanInfo, this.showLeftEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.CopyEnterTimesUpdate, this.showLeftEnterNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.name = "";
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateLevel, this.showLeftEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.CopyEnterTimesUpdate, this.showLeftEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.showLeftEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.SingleTowerGanInfo, this.showLeftEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.CopyEnterTimesUpdate, this.showLeftEnterNum);
            super.disposeImpl(param1);
            return;
        }// end function

        private function checkLeftEnterNum() : void
        {
            var _loc_1:int = 0;
            if (this._isNeedToUpdate)
            {
                if (GameController.autoGuide.hasGuideGroupCopy())
                {
                    _loc_1 = _loc_1 + (3 - Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeTeam));
                }
                if (GameController.autoGuide.hasGuideCopyIcon())
                {
                    _loc_1 = _loc_1 + (3 - Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeSingle));
                }
                if (GameDefConfig.instance.getSystemOpenLevel(49))
                {
                    _loc_1 = _loc_1 + VipUtil.vipCopyLeftNum;
                }
                if (GameController.autoGuide.hasGuideDefenseCopy())
                {
                    _loc_1 = _loc_1 + GroupTowerCopyUtil.getNumByGroup(112);
                }
                if (GameController.autoGuide.hasTeamGuideDefenseCopy())
                {
                    _loc_1 = _loc_1 + GroupTowerCopyUtil.getNumByGroup(138);
                }
                if (LevelCheckUtil.isLevelEnougth(94))
                {
                    _loc_1 = _loc_1 + GroupTowerCopyUtil.getSingleTowerCopyNum();
                }
                if (_loc_1)
                {
                    setIconTxt(_loc_1.toString());
                }
                else
                {
                    setIconTxt("");
                }
                this._isNeedToUpdate = false;
            }
            return;
        }// end function

        private function showLeftEnterNum(param1:Object = null) : void
        {
            this._isNeedToUpdate = true;
            CallLater.addCallBack(this.checkLeftEnterNum);
            return;
        }// end function

        private function showEffect(param1:Object = null) : void
        {
            var _loc_3:Boolean = false;
            var _loc_4:int = 0;
            var _loc_2:* = Cache.instance.copy.copyFirstBloodDic;
            for each (_loc_4 in _loc_2)
            {
                
                if (_loc_4 == ECopyFBType._ECopyFBTypeNotGet)
                {
                    _loc_3 = true;
                    break;
                }
            }
            if (_loc_3)
            {
                this.playEffect();
            }
            else
            {
                this.stopEffect();
            }
            return;
        }// end function

        public function showGroupRwEffect() : void
        {
            if (GroupCopyUtil.hasRws())
            {
                this.playEffect();
            }
            else
            {
                this.stopEffect();
            }
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupCopyOpenByIndex, Cache.instance.group.groupCopyTemporaryIndex));
            return;
        }// end function

        public static function get instance() : GroupCopyIcon
        {
            if (!_instance)
            {
                _instance = new GroupCopyIcon;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
